package com.chis.childcheck;

import com.alibaba.fastjson.JSON;
import com.chis.jm.bean.ChildSynInfoBean;
import com.chis.jm.bean.CrTriggerBean;
import com.chis.jm.bean.TriggerBean;
import com.chis.jm.pojo.Child;
import com.chis.jmdataspark.comm.JedisSerializeUtil;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.Tuple;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

/**
 * 
 * @Description 
 * @Company zwx
 * @author wlj
 * @version 2019年08月28日
 */
public class TestZredis {

    public static void main(String[] args) {
        ShardedJedis jedis = JedisConnect.getInstance().sparkjedisPool.getResource();
        jedis.select(1);
        ChildSynInfoBean bean = new ChildSynInfoBean();
        Child child = new Child();
        child.setChilCode(111111111L);
        List<Child> list = new ArrayList<>();
        list.add(child);
        bean.setChildList(list);
        jedis.zadd("test".getBytes(), 10, JedisSerializeUtil.serialize(bean));

        Set<Tuple> tuples = jedis.zrangeByScoreWithScores("test".getBytes(), 10, 20);
        Iterator<Tuple> iterator = tuples.iterator();
        while (iterator.hasNext()){
            Tuple t = iterator.next();
            System.out.println("score:"+t.getScore());
            ChildSynInfoBean childSynInfoBeanTemp = (ChildSynInfoBean) JedisSerializeUtil.unserialize(t.getBinaryElement());
            String str = JSON.toJSONString(childSynInfoBeanTemp);
            System.out.println(str);
        }


        jedis.close();
    }


}
